import App from './App';
import {
	createSSRApp,
	reactive
} from 'vue'
// 引入vuex
import store from '@/store/index.js';

// 第三方文件引入(lib目录下的全局引入)
import _ from "@/lib/lodash/lodash.js";;
import moment from "@/lib/moment/moment.min.js";

// 全局组件引入
import  yytLoading from '@/components/yyt-loading/yyt-loading.vue'

// 自定义开发文件引入(common目录下的全局引入)
import * as filters from '@/common/vue-filter/vue-filters.js';
import storage from '@/common/unistorage/index.js';
import util from '@/common/util.js';
import bs from '@/common/business/common.js';
import appConfig from '@/common/config/config.js'
import vuexMixin from '@/store/$u.mixin.js'
import JSEncrypt from '@/lib/jsencrypt/jsencrypt.js'
// import common_im from '@/pages/30message/common_im.js'


// 扩展Vue原型
function prototypeEx(app) {
	// vue prototype 扩展
	app.config.globalProperties.$_ = _; // 加入 lodash使用
	app.config.globalProperties.$util = util; // util
	app.config.globalProperties.$moment = moment; // 加入 moment使用
	app.config.globalProperties.$globalData = reactive(App.globalData); // 全局
	app.config.globalProperties.$cw = bs; // 业务js
	app.config.globalProperties.$filters = filters; // 全局过滤
	app.config.globalProperties.$appConfig = appConfig; // appconfig配置
	app.config.globalProperties.$storage = storage; // 用于存储
	app.config.globalProperties.$store = store; // vuex
	app.config.globalProperties.$window = window||{}; // windows对象
	app.config.globalProperties.$encrypt = function (){
		const encrypt = new JSEncrypt();
		let pubKey= encrypt.Base64.myDecode(appConfig.PUBKEY);
		pubKey=decodeURIComponent(pubKey).toString().replace('\x00','');
		let privateKey=encrypt.Base64.myDecode(appConfig.PRIVATEKEY);
		privateKey=decodeURIComponent(privateKey);
		encrypt.setPublicKey(pubKey);
		encrypt.setPublicKey(privateKey);
		return encrypt;
	}(); // vuex
	app.config.globalProperties.$u = {
		vuex: (name, value) => {
			store.commit('$uStore', {
				name,
				value
			})
		}
	}; // vuex的初始化
	app.config.globalProperties.$uni = uni; // uni初始化
	 // common_im.initIm(app); // 初始化goeasy
	return
}

export function createApp() {
	const app = createSSRApp(App);
	prototypeEx(app);
	app.component('yyt-loading',yytLoading);
	app.mixin(vuexMixin);
	return {
		app
	}
}
